home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15698 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.0 KB

  1. Path: ix.netcom.com!news
  2. From: Jane Harper <jharper@ix.netcom.com>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Probs with prototype mixes with Functions
  5. Date: Sat, 20 Apr 1996 09:06:54 -0700
  6. Organization: Netcom
  7. Message-ID: <31790B9E.3EE@ix.netcom.com>
  8. References: <dward.1.000DC9CA@melbpc.org.au>
  9. NNTP-Posting-Host: sjx-ca11-09.ix.netcom.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-NETCOM-Date: Sat Apr 20 11:09:37 AM CDT 1996
  14. X-Mailer: Mozilla 2.01 (Win95; U)
  15.  
  16. Darren Ward wrote:
  17. > Could anyone help me with the following?
  18. > when making a function such as:
  19. > float convert(int celcius)
  20. > {
  21. >     float faranheit;
  22. >     faranheit = ((float)celcius*9/5)+32;
  23. >     return faranheit;
  24. > }
  25.  
  26. When you multiply celcius (cast to float) by 9/5 (an integer division), 
  27. celcius is cast back to an int.  Therefore, your return is an int, not a 
  28. float.  If you want a float return, change 9/5 to 9.0/5.0.  :D
  29.  
  30. BTW, you may also want to check your spelling .. it's celSius and 
  31. FAHRenheit.  ;0
  32.  
  33. J.
  34.